Fix forc-fmt empty if-body + else collapsing onto one line#7628
Fix forc-fmt empty if-body + else collapsing onto one line#7628Dnreikronos wants to merge 4 commits into
Conversation
When an if-block has an empty body and an else clause, the formatter
wrote no newline before the closing brace, producing collapsed output
like `if cond { } else if ...` on a single line.
Write a newline after the empty body when an else clause exists, and
skip block_unindent since close_curly_brace in format_else_opt already
handles it. Guard with LineStyle::Inline to avoid injecting newlines
during width measurement probes.
Closes FuelLabs#7625
Add expr-level test for empty if + else-if and integration tests for empty if + else-if and empty if + else with long lines that prevent inlining.
PR SummaryLow Risk Overview Regression coverage was added in expression and integration tests. Reviewed by Cursor Bugbot for commit 12b35b7. Bugbot is set up for automated code reviews on this repo. Configure here. |
Description
Fixes #7625
forc-fmtcollapses empty if-body + else onto a single line:Root cause: In
format_then_block, when the then-block is empty and has an else clause,block_unindent()was called but no newline was written — so the closing}fromformat_else_optended up on the same line.Fix: Write a newline after the empty body when an else clause exists, and skip
block_unindentsinceclose_curly_braceinformat_else_optalready handles unindentation. Guarded withLineStyle::Inlineto avoid injecting newlines during width measurement probes.Checklist
Breaking*orNew Featurelabels where relevant.